// pages/payMoney/payMoney.js

const app = getApp()
let taskId;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    taskName: '',
    orderMoney: 0,
    money: 0,
    wxpayMoney: 0,
    payMoney: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    taskId = options.taskId;
    console.log("传递参数taskId:"+taskId);
    //查询任务和订单信息
    wx.request({
      url:app.globalData.prefix+'/taskAction/queryTaskOrder?taskId='+taskId+"&openId="+app.globalData.userInfo.openId,
      success:function(res){
        if(res.data.status!="00"){
          wx.$showToast(res.data.errorMsg);
          return;
        }
        self.setData(res.data.result);
      },
      fail:function(e){
        //wx.$showToast("系统错误");
        console.log(e);
      }
    });
  },


  changeTask() {
    wx.navigateTo({
      url:'../publishMerge/publish?taskId='+taskId
    })
  },
  changeNum(e) {
    this.setData({
      [e.currentTarget.dataset.type] : e.detail.value
    })
    console.log(this.data);
  },
  surePay() {
    let self = this;
    let payMoney = self.data.payMoney;
    let wxpayMoney = self.data.wxpayMoney;
    let taskId = self.data.taskId;
    //调用支付方法
    wx.request({
      url:app.globalData.prefix+"/taskAction/taskPay",
      data:{
        openId:app.globalData.userInfo.openId,
        taskId:taskId,
        payMoney:payMoney,
        wxpayMoney:wxpayMoney
      },
      success:function(res){
        if(res.data.status!='00'){
          wx.$showToast(res.data.errorMsg);
          return;
        }
        wx.navigateTo({
          url: '../mySelfTask/mySelfTask?index=1',
        })
      }
    });

  }
})